package logic

import (
	"context"

	"lottery-zero/internal/model"
	"lottery-zero/internal/svc"
	"lottery-zero/internal/types"

	"github.com/tal-tech/go-zero/core/logx"
)

type LottolatestLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLottolatestLogic(ctx context.Context, svcCtx *svc.ServiceContext) LottolatestLogic {
	return LottolatestLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LottolatestLogic) Lottolatest() (*types.LottoLatestReply, error) {
	var lottoTicket model.LotteryTicket
	tx := l.svcCtx.PGDB.Model(&model.LotteryTicket{}).Order("open_date desc").First(&lottoTicket)
	return &types.LottoLatestReply{DrawNum: lottoTicket.DrawNum, OpenDate: lottoTicket.OpenDate.Format("2006-01-02 15:04:05"), Front: lottoTicket.Front, Back: lottoTicket.Back}, tx.Error

}
